package master.photo.service.impl;

import java.util.List;

import master.photo.dao.GenericDAO;
import master.photo.domain.security.AppUser;
import master.photo.service.AppUserService;

import org.apache.commons.collections.CollectionUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.emory.mathcs.backport.java.util.Arrays;

@Service
public class AppUserServiceImpl implements AppUserService {

	@Autowired
	private GenericDAO genericDAO;

	@Override
	public AppUser findByUsername(String username) {
		SimpleExpression expression = Restrictions.eq("username", username);
		List<AppUser> result = genericDAO.findBy(AppUser.class, Arrays
				.asList(new Criterion[] { expression }));

		return CollectionUtils.isNotEmpty(result) ? result.get(0) : null;
	}

}
